<template>
	<view>
		<u-swiper :list="bannerList" keyName="resUrl" indicatorMode="dot" radius="0" :height="height"
			@click="swiperClick" indicator></u-swiper>
	</view>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { LoginCenterApi } from '../api/serves'
import { getCurrentInstance } from 'vue'

// Props 定义
const props = defineProps({
	positionType: {
		type: [String, Number],
		default: null
	},
	height: {
		type: String,
		default: '458rpx'
	}
})

// 响应式数据
const bannerList = ref([])

// 获取全局工具方法
const { proxy } = getCurrentInstance()
const $tool = proxy.$tool

// 获取轮播图数据
const getBannerList = async () => {
	const { code, data, msg } = await LoginCenterApi.getBannerList({
		positionType: props.positionType
	})
	if (code != 1) return $tool.alert(msg)
	bannerList.value = data
}

// 轮播图点击事件
const swiperClick = (e) => {
	const item = bannerList.value[e]
	console.log(e, '轮播点击', item)

	switch (item.jumpType) {
		case 2:
			$tool.jump_nav(item.jumpUrl)
			break
		case 3:
			$tool.toApplet(item.appId, item.jumpUrl)
			break
		case 4:
			$tool.jump_nav('/pages/web-page/web-page?url=' + encodeURIComponent(JSON.stringify(item.jumpUrl)))
			break
		case 5:
			$tool.openChannelsActivity(item.spId, item.feedId)
			break
	}
}

// 生命周期
onMounted(() => {
	getBannerList()
})
</script>

<style></style>
